/*dom*/
// 注册事件
$(document).on('click','#zc',function () {
    const account = document.getElementById('account').value;
    const password = document.getElementById('password').value;
    const repassword = document.getElementById('repassword').value;
    const dd = {
        account: account,
        password: password,
        repassword: repassword
    };
    // 发送 POST 请求
    axios({
        method: 'post',
        url: '/api/user/register',
        data: dd
    }).then(function (response) {
        console.log(response);
        if(response.data.code === 1){
            alert('注册成功');
            // 页面逻辑
        }else{
            alert(response.data.code+'+'+response.data.message);
            // 页面逻辑
        }
    }).catch(function (error) {
        console.log(error);
    });
});

$(document).on('click','#dl',function () {
    const account = document.getElementById('account').value;
    const password = document.getElementById('password').value;
    const dd = {
        account: account,
        password: password
    };
    axios({
        method: 'post',
        url: '/api/user/login',
        data: dd
    }).then(function (response) {
        console.log(response);
        document.getElementById('userName').innerText = "用户名："+response.data.userinfo.username;
        document.getElementById('userId').innerText = "用户ID："+response.data.userinfo._id;
        if(!document.getElementsByClassName('login-content')[1]){
            document.getElementsByClassName('login-content')[0].classList.add('hide');
        }

        window.location.reload();
    });
});

$(document).on('click','#login_out',function () {
    axios({
        method: 'post',
        url: '/api/user/loginOut'
    }).then(function (response) {
        console.log(response);
        if(!response.data.code){
            window.location.reload();
        }
    }).catch(function (error) {
        console.log(error);
    });
})
